package com.example.studentmanage.dao;

import com.example.studentmanage.pojo.Course;
import com.example.studentmanage.pojo.Student;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class CourseDao {
    private static Map<Integer, Course> courseMap=null;

    static {
        courseMap=new HashMap<Integer, Course>();
        courseMap.put(1,new Course(1,"java","jack"));
        courseMap.put(2,new Course(2,"C++","lily"));
        courseMap.put(3,new Course(3,"python","mack"));
    }

    public Collection<Course> getAllCourse(){
        return courseMap.values();
    }

    public Course getCourseByid(Integer id){
        return courseMap.get(id);
    }

    public static Integer inid=5;
    public void save(Course course){
        if (course.getId()==null){
            course.setId(inid++);
        }
        courseMap.put(course.getId(),course);
    }

    public void delete(Integer id){
        courseMap.remove(id);
    }

}
